/**删除前缀=后缀，前、后缀要求所有字符都相同
 * @param {string} s
 * @return {number}
 * 如 s = "aabccabba" => 'cca' 删除前缀aa和后缀a，删除前缀b和后缀bb
 *    s = "cabaabac"  => ''
 */
var minimumLength = function (s) {
    // 双指针
    let left = 0, right = s.length - 1
    while (left < right && s[left] == s[right]) {
        const str = s[left]
        // 前缀有相同字符时继续向后搜索
        while (left <= right && s[left] == str) {
            left++
        }
        // 后缀有相同字符时继续向前搜索
        while (left <= right && s[right] == str) {
            right--
        }
    }
    // 返回剩余字符的长度
    return right - left + 1
};